import { Component ,Input} from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TopicInfo, RowInfo } from '../../models/quesinfo';
/**
 * Generated class for the QuestionMatrixProportionPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-question-matrix-proportion',
  templateUrl: 'question-matrix-proportion.html',
})
export class QuestionMatrixProportionPage {
  @Input() topic: TopicInfo;@Input() poneSet: Array<any>;
  @Input() topicIndex;
  topicIndexshow;

  arValue = [{key: 'aaa', value: 30}, {key: 'bbb', value: 30}, {key: 'ccc', value: 40}];

  constructor(public navCtrl: NavController, public navParams: NavParams) {

  }

  ngOnInit(): void {


    this.topicIndexshow = this.topicIndex + 1;
  }

  inputdata(s, i, j) {
    if (i < 0) {
      s.target.value=0;
      i=0;
    }
    if (i > 100) {
      i=100;
     s.target.value=100;
    }
    if(isNaN(i)){
      s.target.value=0;
      i=0;
    }
    let tempallcount = 0;
    this.topic.listRow.forEach(a => {
      tempallcount +=Math.ceil(parseFloat(a.TemInput));
    })
    if(tempallcount>100){
      s.target.value=0;
      i=0;
    }
    this.topic.listRow[j].TemResult = Math.round((Math.ceil(i) * this.topic.FScore * 0.01)).toString();



  }


  datachange(e, i) {
    let tempallcount = 0;
    this.topic.listRow.forEach(a => {
      tempallcount += parseInt(a.TemResult);
    })
    if(tempallcount>this.topic.FScore){
      let countr=this.topic.listRow.length;
    const otherValue = (this.topic.FScore - parseFloat(this.topic.listRow[i].TemResult)) / (countr-1);
    this.topic.listRow.forEach(a => {
      if (this.topic.listRow[i].FROptionId !== a.FROptionId) {
        a.TemResult = Math.floor(otherValue).toString();
      }
    });

    }
  }
}

